﻿using System;

namespace ToMIC.Identity
{
    public class EmailContact : IEmailContact
    {
        public EmailContact()
        {
            FullName = string.Empty;
            Email = string.Empty;
        }

        public EmailContact(IEmailContact contact)
        {
            FullName = contact.FullName;
            Email = contact.Email;
        }
        public string Email { get; set; }
        public string FullName { get; set; }

        public override string ToString()
        {
            return string.Format("{0}<{1}>;", FullName, Email);
        }

        public static EmailContact Parse(string s)
        {
            int lt = s.IndexOf('<');
            int gt = s.IndexOf('>');
            var emailContact = new EmailContact();
            emailContact.FullName = s.Substring(0, lt).Trim();
            emailContact.Email = s.Substring(lt + 1, gt - lt - 1).Trim();
            return emailContact;
        }
    }
}
